<template>
  <Dialog :title="dialogTitle" v-model="dialogVisible" scroll max-height="600px" @open="open">
    <el-form
      ref="formRef"
      :model="formData"
      :rules="formRules"
      label-width="100px"
      v-loading="formLoading"
    >
      <el-form-item label="期刊名称:" prop="journalName">
        {{ formData.journalName }}
      </el-form-item>
      <el-form-item label="期刊编号" prop="journalCode">
        {{ formData.journalCode }}
      </el-form-item>
      <el-form-item label="ISSN/ISBN:" prop="sn">
        {{ formData.sn }}
      </el-form-item>
      <el-form-item label="出版社:" prop="journalFrom">
        {{ formData.journalFrom }}
      </el-form-item>
      <el-form-item label="语言:" prop="language">
        {{ formData.language }}
      </el-form-item>
      <el-form-item label="出版频率:" prop="frequency">
        <dict-tag :type="DICT_TYPE.JOURNAL_FREQUENCY" :value="formData.frequency" />
      </el-form-item>
      <el-form-item label="主题分类:" prop="topicType">
        <dict-tag :type="DICT_TYPE.JOURNAL_TYPE" :value="formData.topicType" />
      </el-form-item>
      <el-form-item label="期刊封面:" prop="mainImage">
        <el-image
          style="width: 44px; height: 44px;"
          :src="formData.mainImage"
          :preview-src-list="[formData.mainImage]"
          fit="cover"
        />
      </el-form-item>
      <el-form-item label="期刊文件:" prop="file">
        <UploadFile v-model="formData.file" disabled />
      </el-form-item>
      <el-divider content-position="left">版本与卷期</el-divider>
      <el-form-item label="卷号:" prop="volumeNumber">
        {{ formData.volumeNumber }}
      </el-form-item>
      <el-form-item label="期号:" prop="issue">
        {{ formData.issue }}
      </el-form-item>
      <el-form-item label="期刊发行时间" prop="publishYear">
        {{ formData.publishYear }}
      </el-form-item>
      <el-form-item label="期刊发行地点" prop="position">
        {{ formData.position }}
      </el-form-item>
      <el-form-item label="期刊发行内容" prop="content">
        {{ formData.content }}
      </el-form-item>
      <el-form-item label="期刊作者" prop="author">
        {{ formData.author }}
      </el-form-item>
      <el-form-item label="页码范围:" prop="pageRange">
        {{ formData.pageRange }}
      </el-form-item>
      <el-divider content-position="left">订购信息</el-divider>
      <el-form-item label="期刊来源:" prop="source">
        <dict-tag :type="DICT_TYPE.JOURNAL_SOURCE" :value="formData.source" />
      </el-form-item>
      <el-form-item label="期刊状态:" prop="status">
        <dict-tag :type="DICT_TYPE.JOURNAL_STATUS" :value="formData.status" />
      </el-form-item>
      <el-form-item label="订购来源:" prop="orderSource">
        {{ formData.orderSource }}
      </el-form-item>
      <el-form-item label="订购日期:" prop="orderTime">
        {{ formatDate(formData.orderTime) }}
      </el-form-item>
      <el-divider content-position="left">存储信息</el-divider>
      <el-form-item label="访问链接:" prop="webUrl">
        {{ formData.webUrl }}
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="dialogVisible = false">取 消</el-button>
    </template>
  </Dialog>
</template>
<script setup lang="ts">
import { DICT_TYPE } from '@/utils/dict'
import { propTypes } from '@/utils/propTypes'
import { formatDate } from '@/utils/formatTime'
import { JournalApi, JournalVO } from '@/api/dr/journal'

/** 期刊信息 表单 */
defineOptions({ name: 'JournalDetail' })
const emit = defineEmits(['update:visible'])
const props = defineProps({
  visible: propTypes.bool.def(false),
  data: propTypes.object.def({}),
})
// 弹窗的是否展示
const dialogVisible = computed({
  get: () => props.visible,
  set: (val) => {
    emit('update:visible', val)
  },
})
// 弹窗的标题
const dialogTitle = ref('期刊信息查看')
const formLoading = ref(false) // 表单的加载中：1）修改时的数据加载；2）提交的按钮禁用
const formData = ref<JournalVO | any>({})
const formRules = reactive({
  journalName: [
    {
      required: true,
      message: '请输入期刊名称',
      trigger: 'blur',
    },
  ],
  journalCode: [
    {
      required: true,
      message: '请输入期刊编号',
      trigger: 'blur',
    },
  ],
})
const formRef = ref() // 表单 Ref

const getDetail = () => {
  formLoading.value = true
  JournalApi.getJournal(props.data.ywid).then((data) => {
    console.log('getDetail', data)
    formData.value = data
  }).finally(() => {
    formLoading.value = false
  })
}
const open = () => {
  getDetail()
}
</script>